/*
 * OpenParts
 * A dynamic-loading components framework for GWT
 * Copyright (C) 2011 Christophe Bouthier  [chris{AT}binary-gastronome{DOT}fr]
 *
 * This work is partially based on work I have done at INRIA (http://www.inria.fr) 
 * in the context of the Qualipso European Project (http://qualipso.org/),
 * The work done at INRIA is Copyright (C) 2006-2011 INRIA
 *
 * This work is distributed under the LGPL version 3
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3
 * as published by the Free Software Foundation. See the GNU
 * Lesser General Public License in LGPL.txt for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package fr.openparts.opshowcase.eventmodule.client.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.Widget;

import fr.openparts.OpenParts.client.OPParams;
import fr.openparts.OpenParts.client.OPShell;
import fr.openparts.opshowcase.eventmodule.client.presenter.EventModulePresenter;
import fr.openparts.opshowcase.eventmodule.client.resources.EventModuleResources;

/**
 * View of General Module of Dispatch Event for OpenParts Showcase.
 * 
 * @author Christophe Bouthier [chris{AT}binary-gastronome{DOT}fr]
 * @creation.date 07 February 2011
 */
public class EventModuleView extends Composite {

    interface EventModuleViewUiBinder extends UiBinder<Widget, EventModuleView> {}
    private static EventModuleViewUiBinder uiBinder = GWT.create(EventModuleViewUiBinder.class);

    protected EventModulePresenter presenter;

    @UiField
    protected EventModuleResources resources;

    @UiField
    protected Button dispatchEvent1;
    @UiField
    protected Button dispatchEvent2;
    @UiField
    protected Button dispatchEvent3;
    @UiField
    protected Button dispatchEvent4;
    @UiField
    protected Button dispatchEvent5;
    @UiField
    protected Button dispatchEvent6;
    @UiField
    protected Button displayModule2;
    @UiField
    protected Button dispatchEventMod1;
    @UiField
    protected Button dispatchEventMod2;
    @UiField
    protected Button dispatchEventMod;
    
    @UiField
    protected LayoutPanel module1;
    @UiField
    protected LayoutPanel module2;
    
    /**
     * Constructor.
     */
    public EventModuleView(final EventModulePresenter presenter) {
        initWidget(uiBinder.createAndBindUi(this));
        resources.style().ensureInjected();
        this.presenter = presenter;
        presenter.displayModule("1", module1);
    }
    
    @UiHandler("dispatchEvent1")
    public void dispatchEvent1(final ClickEvent event) {
        OPShell.dispatchEventTo("eventmodule1", "event", new OPParams("msg", "1"));
    }
    
    @UiHandler("dispatchEvent2")
    public void dispatchEvent2(final ClickEvent event) {
        OPShell.dispatchEventTo("eventmodule2", "event", new OPParams("msg", "2"));
    }
    
    @UiHandler("dispatchEvent3")
    public void dispatchEvent3(final ClickEvent event) {
        OPShell.dispatchEvent("event", new OPParams("msg", "3"));
    }
    
    @UiHandler("dispatchEvent4")
    public void dispatchEvent4(final ClickEvent event) {
        OPShell.dispatchEventTo("eventmodule1", "event", new OPParams("msg", "4"));
    }
    
    @UiHandler("dispatchEvent5")
    public void dispatchEvent5(final ClickEvent event) {
        OPShell.dispatchEventTo("eventmodule2", "event", new OPParams("msg", "5"));
    }
    
    @UiHandler("dispatchEvent6")
    public void dispatchEvent6(final ClickEvent event) {
        OPShell.dispatchEvent("event", new OPParams("msg", "6"));
    }
    
    @UiHandler("displayModule2")
    public void displayModule2(final ClickEvent event) {
        presenter.displayModule("2", module2);
    }

    @UiHandler("dispatchEventMod1")
    public void dispatchEventMod1(final ClickEvent event) {
        OPShell.dispatchEvent("mod1");
    }
    
    @UiHandler("dispatchEventMod2")
    public void dispatchEventMod2(final ClickEvent event) {
        OPShell.dispatchEvent("mod2");
    }
    
    @UiHandler("dispatchEventMod")
    public void dispatchEventMod(final ClickEvent event) {
        OPShell.dispatchEvent("mod");
    }
    
}
